//定义表示记分牌的类
class ScorePanel {
    //score和level用来记录分数和等级
    score: number = 0;
    level: number = 1;
    //分数和等级所在的元素，在构造函数中进行初始化
    scoreEle: HTMLElement;
    levelEle: HTMLElement;

    //设置一个变量等级
    maxLevel: number;
    //设置一个变量表示多少分时升级
    upScore: number
    //分数和等级所在的元素，在钩爪函数中进行初始化
    constructor(maxLevel: number = 10, upScore: number = 10) {
        this.scoreEle = document.getElementById('score') as HTMLElement;
        this.levelEle = document.getElementById('level') as HTMLElement;
        this.maxLevel = maxLevel;
        this.upScore=upScore
    }

    //设置一个加分的方法
    addScore() {
        //使分数自增，且是字符串类型
        this.scoreEle.innerHTML = String(++this.score)
        //判断分数是多少
        if (this.score % this.upScore === 0) this.levelUp();
    }

    //提升等级的方法
    levelUp() {
        //添加等级限制
        if (this.level < this.maxLevel) 
        this.levelEle.innerHTML = String(++this.level)
    }
}
export default ScorePanel